patientRelationshipModule.controller("RevisitManagementCtrl", ["$log", "$filter", "$q", "$scope", "$timeout", "appNav", "adminOfficeSvc", "formatUtil", "apptUtil", "patientUtil", "patientSvc", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var v = function(n) {
            f.goToPatient(n.patient.id)
        },
        l = function() {
            var n = moment(r.startDate).format("YYYY-MM-DD"),
                t = moment(r.endDate).add(1, "d").format("YYYY-MM-DD");
            e.getRevisits(undefined, r.currentOfficeId, r.revisitType, r.revisitStatus, -1, r.currentVisitorName, n, t).success(function(n) {
                o.formatAdminOfficeRevisits(n, {
                    abbreviation: "officeAbbr",
                    method: "revisitMethodStr",
                    type: "revisitTypeStr",
                    state: "revisitStateStr",
                    recordCreatedTime: "date",
                    planDate: "date"
                });
                r.adminOfficeRevisits = n;
                r.hasRevisits = n && n.length > 0;
                u(function() {
                    r.noDataMessage = n && n.length > 0 ? "" : "没有找到符合的记录"
                }, 300);
                a()
            })
        },
        a = function() {
            var n = [],
                t = [];
            _.each(r.adminOfficeRevisits, function(n) {
                t.push(n.patientId)
            });
            c.getPatientsHeadInfo(t).then(function(t) {
                angular.forEach(r.adminOfficeRevisits, function(i) {
                    var u = y(i),
                        r;
                    u && (r = _.find(t.data, {
                        id: i.patientId
                    }), i.patientHead = r, n.push(i))
                });
                r.filteredRevisits = n
            })
        },
        y = function(n) {
            if (!r.searchText) return !0;
            return n.nameCode && n.nameCode.indexOf(r.searchText) > -1 || n.mobile && n.mobile.indexOf(r.searchText) > -1 || n.patientName.indexOf(r.searchText) > -1
        },
        p = function(n, t) {
            t = t || "d";
            var i = moment(r.date).add(n, t).toDate();
            r.date = i;
            u(function() {
                l()
            }, 100)
        },
        w = function(n) {
            r.revisitId = n.id;
            r.patientId = n.patientId;
            r.isShowRevisitEditDialog = !0
        },
        b = function(n) {
            return n.state == 0
        };
    (function() {
        r.goToPatient = v;
        r.loadRevisits = l;
        r.date = Ares.today();
        r.navigate = p;
        r.matchSearch = a;
        r.isInitialized = !1;
        r.updateRevisit = w;
        r.canEdit = b;
        r.$watch("date", function() {
            r.refreshDate()
        })
    })()
}]);
patientRelationshipModule.directive("revisitManagementView", ["$log", "$timeout", "$filter", "$window", "appNav", "officeSvc", "apptUtil", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "RevisitManagementCtrl",
        templateUrl: "/app/patient-relationship/views/revisit/revisit-management-view.html",
        scope: {
            officeId: "="
        },
        link: function(n, i) {
            var b = Ares.kendoGridUtil(r, n),
                e = !1,
                s = function() {
                    var t, i;
                    n.searchText || (n.filteredRevisits = n.adminOfficeRevisits);
                    n.filteredRevisits && (t = [{
                        text: "回访",
                        exec: n.updateRevisit,
                        canExec: n.canEdit
                    }, ], e = !0, i = $(window).height() - 180, n.gridOption = {
                        resizable: !0,
                        model: {
                            id: "id"
                        },
                        columns: [],
                        height: i
                    }, n.gridOption.columns.push({
                        field: "patient.nameCode",
                        title: "姓名",
                        width: "102px",
                        sortable: !1,
                        index: 1,
                        code: "patientName",
                        attributes: {
                            "class": "patient-td",
                            style: "padding: 0"
                        },
                        template: function() {
                            return '<ares-patient-namecard patient="dataItem.patientHead" appt="dataItem" mode="noIcon" nav-enabled="true"><\/ares-patient-namecard>'
                        }
                    }, {
                        field: "mobile",
                        title: "联系电话",
                        width: "110px"
                    }, {
                        field: "abbreviation",
                        title: "门店",
                        width: "110px"
                    }, {
                        field: "recordCreatedTimeStr",
                        title: "创建日期",
                        width: "100px"
                    }, {
                        field: "planDateStr",
                        title: "计划时间",
                        width: "100px"
                    }, {
                        field: "revisitTypeStr",
                        title: "回访类型",
                        width: "90px"
                    }, {
                        field: "transactionNames",
                        title: "回访项目",
                        width: "110px"
                    }, {
                        field: "revisitStateStr",
                        title: "回访状态",
                        width: "73px"
                    }, {
                        field: "revisitMethodStr",
                        title: "回访方式",
                        width: "73px"
                    }, {
                        field: "visitorName",
                        title: "回访人",
                        width: "90px"
                    }, {
                        title: "操作",
                        index: 80,
                        code: "apptOperation1",
                        isHidden: !1,
                        width: "80px",
                        template: function(n) {
                            return n.actionCommands || (n.actionCommands = t), '<ares-command-group commands="::dataItem.actionCommands" tag="::dataItem"><\/ares-command-group>'
                        },
                        attributes: {
                            "class": "cell-crowded",
                            style: "min-width:110px;padding: 0"
                        }
                    }), o())
                },
                h = function(t, i, r) {
                    n.$apply(function() {
                        var n = findFollowupPatient(r);
                        switch (i) {
                            case "goToPatient":
                                u.goToPatient(n.patientId)
                        }
                    })
                },
                c = function() {
                    v();
                    a();
                    var r = i.find("#daySelectAdminOfficeBtn");
                    r.datepicker({
                        orientation: "top auto",
                        language: "zh-CN",
                        todayHighlight: !0
                    }).on("changeDate", function(i) {
                        $("#daySelectAdminOfficeBtn").datepicker("hide");
                        n.isInitialized ? n.isInitialize = !1 : t(function() {
                            n.date = i.date;
                            n.loadRevisits()
                        }, 100)
                    });
                    r.datepicker("setDate", moment(n.date).format(n.dateFormat))
                },
                l = function() {
                    $("#daySelectAdminOfficeBtn").datepicker("update", moment(n.date).format("YYYY-MM-DD"))
                },
                a = function() {
                    f.list().success(function(t) {
                        var r = t,
                            u;
                        r.splice(0, 0, {
                            id: -1,
                            abbreviation: "全部"
                        });
                        u = i.find("#officeInput");
                        u.kendoDropDownList({
                            dataSource: r,
                            placeholder: "",
                            dataTextField: "abbreviation",
                            dataValueField: "id",
                            select: function(t) {
                                var i = this.dataItem(t.item.index());
                                n.currentOfficeId = i.id;
                                n.loadRevisits()
                            }
                        })
                    })
                },
                v = function() {
                    var t = i.find("#revisitTypeInput");
                    t.kendoDropDownList({
                        dataSource: [{
                            typeValue: -1,
                            typeName: "请选择类型"
                        }, {
                            typeValue: 1,
                            typeName: "预约未到"
                        }, {
                            typeValue: 2,
                            typeName: "沉睡客户"
                        }, {
                            typeValue: 3,
                            typeName: "未消费回访"
                        }, {
                            typeValue: 4,
                            typeName: "消费后回访"
                        }],
                        placeholder: "",
                        dataTextField: "typeName",
                        dataValueField: "typeValue",
                        select: function(t) {
                            var i = this.dataItem(t.item.index());
                            n.revisitType = i.typeValue;
                            n.loadRevisits()
                        }
                    })
                },
                o = function() {
                    var r = i.find("#adminOfficeRevisitList"),
                        t = r.data("kendoGrid");
                    t && t.dataSource.data(n.filteredRevisits)
                },
                y = function(t) {
                    n.revisitStatus = t;
                    n.loadRevisits()
                },
                p = function() {
                    n.revisitId = null;
                    n.patientId = null;
                    n.isShowRevisitEditDialog = !0
                },
                w = function() {
                    n.isShowRevisitEditDialog = !1
                };
            (function() {
                n.searchText = null;
                n.revisitStatus = -1;
                n.currentOfficeId = -1;
                n.revisitType = 0;
                n.onCommandClick = h;
                n.refreshDate = l;
                n.switchState = y;
                n.startDate = Ares.today();
                n.endDate = Ares.today();
                c();
                n.addRevisit = p;
                n.hideRevisitEditDialog = w;
                n.isShowRevisitEditDialog = !1;
                n.selectedRevisit = {};
                n.$watch("filteredRevisits", function() {
                    e ? o() : (n.loadRevisits(), n.filteredRevisits && s())
                })
            })()
        }
    }
}]);